<script type="text/javascript">
tinyMCE.init({
		// General options
		mode : "exact",
		elements : "elm1",
		theme : "advanced",
		skin : "o2k7",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
tinyMCE.init({
		// General options
		mode : "exact",
		elements : "elm2",
		theme : "advanced",
		skin : "o2k7",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
tinyMCE.init({
		// General options
		mode : "exact",
		elements : "elm3",
		theme : "advanced",
		skin : "o2k7",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
tinyMCE.init({
		// General options
		mode : "exact",
		elements : "elm4",
		theme : "advanced",
		skin : "o2k7",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>

<?php
$id = $_REQUEST['_d'];
$page = $_REQUEST['page'];

if($_REQUEST['_a'] != "u" && $_REQUEST['_a'] != "d")
{
$q = mysql_fetch_array(mysql_query("select * from directory where Id='$id'"));
?>
<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>

<script type="text/javascript" src="includes/fancybox/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="includes/fancybox/jquery.fancybox-1.3.1.js"></script>
<link rel="stylesheet" type="text/css" href="includes/fancybox/jquery.fancybox-1.3.1.css" media="screen" />
<link rel="stylesheet" href="includes/fancybox_style.css" />

<script type="text/javascript">
		$(document).ready(function() {
			/*
			*   Examples - images
			*/

			$("a#1").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#2").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#3").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#4").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#5").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});
			$("a#6").fancybox({
				'titleShow'		: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});

			/*
			*   Examples - various
			*/

			$("#various1").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
				'width'				: '75%',
				'height'			: '75%',
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

			$("#various4").fancybox({
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		});
	</script>

<form name="up" action="index.php?tc=listing_view&_d=<?php echo $id;?>&page=<?php echo $page;?>&_a=u" method="post">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left">Business Directory</div>
        <div style="float:right"><a href="index.php?tc=listing&page=<?php echo $page;?>">Back</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Business Name</td>
    <td align="left"><input type="text" name="businessname" value="<?php echo $q['BusinessName'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="150">Description</td>
    <td align="left"><textarea name="desc" id="elm1" cols="80" rows="5" wrap="soft"><?php echo $q["Description"];?></textarea></td>
</tr>
<tr>
	<td align="right" width="150">Opening Hours</td>
    <td align="left"><textarea name="openinghours" id="elm2" cols="80" rows="5" wrap="soft"><?php echo $q["OpeningHours"];?></textarea></td>
</tr>
<tr>
	<td align="right" width="150">Location</td>
    <td align="left"><input type="text" name="location" value="<?php echo $q['Location'];?>" /></td>
</tr>
<tr>
	<td align="right" width="150">Listing Level</td>
    <td align="left"><?php if($q["ListingLevel"]==1) echo "Standard"; else echo "Premium";?></td>
</tr>
<tr>
	<td align="right" width="150">Category</td>
    <td align="left">
    	<table width="100%" align="center" border="0">
        <?php
				$query1 = mysql_query("select * from category");

				while($f = mysql_fetch_array($query1))
				{
					
					if($i % 2 == 0)
					{ 
					?>
                    	<tr>
						<td align="left"><input type="checkbox" name="cat[]" value="<?php echo $f['Id'];?>" 
						<?php
							$catcou = split(",",$q['Category']);
							foreach($catcou as $cg)
							{
								if($cg == $f['Id']) { echo "checked"; }
							}
						?> 
						  />&nbsp; <?php echo $f['Name']?></td>
                 	<?php  }
					else
					{ ?>
							<td align="left"><input type="checkbox" name="cat[]" value="<?php echo $f['Id'];?>" 
							<?php
								$catcou = split(",",$q['Category']);
								foreach($catcou as $cg)
								{
									if($cg == $f['Id']) { echo "checked"; }
								}
							?>  />&nbsp; <?php echo $f['Name']?></td>
                       	</tr>     						
					<?php }
					$i++;
                } ?>
      	</table>          
    </td>
</tr> 
<tr>
	<td align="right" width="150">URL</td>
    <td align="left"><input type="text" name="url" value="<?php echo $q["URL"];?>" /></td>
</tr> 
<tr>
	<td align="right" width="150">Logo</td>
    <td align="left"><img src="../directoryimage/logo/<?php echo $q["Logo"];?>" border="0"></td>
</tr> 
<tr>
	<td align="right" width="150">Keywords</td>
    <td align="left"><textarea name="keywords" cols="80" id="elm3" rows="3" wrap="soft"><?php echo $q["Keywords"];?></textarea></td>
</tr> 
<tr>
    <td align="right" valign="top">ImgPriority</td>
    <td align="left">
        <input type="radio" name="ImgPriority" value="1" <?php if($q["ImgPriority"]==1) echo "checked";?>>&nbsp;Priority&nbsp;&nbsp;&nbsp;
        <input type="radio" name="ImgPriority" value="2" <?php if($q["ImgPriority"]==2) echo "checked";?>>&nbsp;Default
    </td>
</tr>  
<tr>
	<td align="right" width="150">Template Images</td>
    <td align="left">
    	<?php
		if($q["TemplateImage1"] != "") { ?> <a id="1" href="../directoryimage/<?php echo $q['TemplateImage1'];?>"><img src="../directoryimage/thumb/<?php echo $q['TemplateImage1'];?>" border="0"></a><?php }
		if($q["TemplateImage2"] != "") { ?>  <a id="2" href="../directoryimage/<?php echo $q['TemplateImage2'];?>"><img src="../directoryimage/thumb/<?php echo $q['TemplateImage2'];?>" border="0"></a><?php }
		if($q["TemplateImage3"] != "") { ?>  <a id="3" href="../directoryimage/<?php echo $q['TemplateImage3'];?>"><img src="../directoryimage/thumb/<?php echo $q['TemplateImage3'];?>" border="0"></a><?php }
		if($q["TemplateImage4"] != "") { ?>  <a id="4" href="../directoryimage/<?php echo $q['TemplateImage4'];?>"><img src="../directoryimage/thumb/<?php echo $q['TemplateImage4'];?>" border="0"></a><?php }
		if($q["TemplateImage5"] != "") { ?>  <a id="5" href="../directoryimage/<?php echo $q['TemplateImage5'];?>"><img src="../directoryimage/thumb/<?php echo $q['TemplateImage5'];?>" border="0"></a><?php }
		if($q["TemplateImage6"] != "") { ?>  <a id="6" href="../directoryimage/<?php echo $q['TemplateImage6'];?>"><img src="../directoryimage/thumb/<?php echo $q['TemplateImage6'];?>" border="0"></a><?php }
		?>
    </td>
</tr>   
<tr>
	<td align="right" width="150">Contact Email</td>
    <td align="left"><input type="text" name="email" value="<?php echo $q['ContactEmail'];?>" /></td>
</tr>  
<tr>
	<td align="right" width="150">Show Email</td>
    <td align="left">
    	<input type="radio" value="1" name="ShowEmail" <?php if($q["ShowEmail"]==1) echo "checked";?> />&nbsp;Yes&nbsp;&nbsp;
        	<input type="radio" value="0" name="ShowEmail" <?php if($q["ShowEmail"]==0) echo "checked";?> />No
    </td>
</tr> 
<tr>
	<td align="right" width="150">Address1</td>
    <td align="left"><input type="text" name="address1" value="<?php echo $q['Address1'];?>" /></td>
</tr> 
<tr>
	<td align="right" width="150">Address2</td>
    <td align="left"><input type="text" name="address2" value="<?php echo $q['Address2'];?>" /></td>
</tr> 
<tr>
	<td align="right" width="150">City</td>
    <td align="left"><input type="text" name="city" value="<?php echo $q['City'];?>" /></td>
</tr> 
<tr>
	<td align="right" width="150">State</td>
    <td align="left"><input type="text" name="state" value="<?php echo $q['State'];?>" /></td>
</tr>
<tr>
	<td align="right" width="150">Postcode</td>
    <td align="left"><input type="text" name="postcode" value="<?php echo $q['Postcode'];?>" /></td>
</tr> 
<tr>
	<td align="right" width="150">Phone</td>
    <td align="left"><input type="text" name="phone" value="<?php echo $q['Phone'];?>" /></td>
</tr> 
<tr>
	<td align="right" width="150">Fax</td>
    <td align="left"><input type="text" name="fax" value="<?php echo $q['Fax'];?>" /></td>
</tr>
<tr>
	<td align="right" width="150">Business Description</td>
    <td align="left"><textarea name="businessdesc" cols="80" id="elm4" rows="5" wrap="soft"><?php echo $q['BusinessDesc'];?> </textarea></td>
</tr> 
<tr>
	<td align="right" width="150">Amount</td>
    <td align="left">$<?php echo $q["Amount"];?></td>
</tr> 
<tr>
	<td align="right" width="150">TransactionId</td>
    <td align="left"><?php echo $q["TransactionId"];?></td>
</tr>
<tr>
	<td align="right" width="150">Inserted Date</td>
    <td align="left"><?php echo $q["InsertedDate"];?></td>
</tr>
<tr>
	<td align="right" width="150">Status</td>
    <td align="left">
    	<select name="status">
        	<option value="0" <?php if($q["Status"]==0) echo "selected";?>>Pending</option>
            <option value="1" <?php if($q["Status"]==1) echo "selected";?>>Approved</option>
       	</select>     
    </td> 
</tr> 
<tr>
	<td colspan="2" style="padding-left:155px;">
    	<input type="submit" value="Update" >
    </td>
</tr>        
</table>   
</form> 
<?php
}

if($_REQUEST['_a']=="u")
{
	$status = $_POST['status'];
	$businessname = $_POST['businessname'];
	$desc = $_POST['desc'];
	$openinghours = $_POST['openinghours'];
	$location = $_POST['location'];
	$url = $_POST['url'];
	$keywords = $_POST['keywords'];
	$ImgPriority = $_POST['ImgPriority'];
	$email = $_POST['email'];
	$ShowEmail = $_POST['ShowEmail'];
	$address1 = $_POST['address1'];
	$address2 = $_POST['address2'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$postcode = $_POST['postcode'];
	$phone = $_POST['phone'];
	$fax = $_POST['fax'];
	$businessdesc = $_POST['businessdesc'];
	$cat = $_POST['cat'];
	
	$catcount = count($cat);
	for($i=0;$i<$catcount;$i++)
	{
		if($category=="") $category = $cat[$i];
		else $category = $category.",".$cat[$i];
	}
	
	mysql_query("update directory set BusinessName='$businessname', Description='$desc', OpeningHours='$openinghours', Location='$location', URL='$url', Keywords='$keywords', ImgPriority='$ImgPriority', ContactEmail='$email', ShowEmail='$ShowEmail', Address1='$address1', Address2='$address2', City='$city', State='$state', Postcode='$postcode', Phone='$phone', Fax='$fax', BusinessDesc='$businessdesc', Status='$status', ApprovedDate=now(), Category='$category' where Id='$id'");
	//header("location:index.php?tc=listing_view&_d=$id&page=$page&_s=1");
	echo "<script>window.location='index.php?tc=listing_view&_d=$id&page=$page&_s=1'</script>";
}
if($_REQUEST['_a']=="d")
{
	$q = mysql_fetch_array(mysql_query("select * from directory where Id='$id'"));
	$path1 = "../directoryimage/".$q['TemplateImage1'];
	$thumb_path1 = "../directoryimage/thumb/".$q['TemplateImage1'];
	@unlink($path1);
	@unlink($thumb_path1);
	$path2 = "../directoryimage/".$q['TemplateImage2'];
	$thumb_path2 = "../directoryimage/thumb/".$q['TemplateImage2'];
	@unlink($path2);
	@unlink($thumb_path2);
	$path3 = "../directoryimage/".$q['TemplateImage3'];
	$thumb_path3 = "../directoryimage/thumb/".$q['TemplateImage3'];
	@unlink($path3);
	@unlink($thumb_path3);
	$path4 = "../directoryimage/".$q['TemplateImage4'];
	$thumb_path4 = "../directoryimage/thumb/".$q['TemplateImage4'];
	@unlink($path4);
	@unlink($thumb_path4);
	$path5 = "../directoryimage/".$q['TemplateImage5'];
	$thumb_path5 = "../directoryimage/thumb/".$q['TemplateImage5'];
	@unlink($path5);
	@unlink($thumb_path5);
	$path6 = "../directoryimage/".$q['TemplateImage6'];
	$thumb_path6 = "../directoryimage/thumb/".$q['TemplateImage6'];
	@unlink($path6);
	@unlink($thumb_path6);
	$logopath = "../directoryimage/logo/".$q['Logo'];
	@unlink($logopath);
	mysql_query("delete from directory where Id='$id'");
	//header("location:index.php?tc=listing&page=$page&_s=2");
	echo "<script>window.location='index.php?tc=listing&page=$page&_s=2'</script>";
}
?>